package com.erp.erp_mask.controller;

import com.erp.erp_mask.pojo.TSupplier;
import com.erp.erp_mask.pojo.TUsers;
import com.erp.erp_mask.service.TSupplierService;
import com.erp.erp_mask.vo.Result;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @BelongsProject: erp
 * @BelongsPackage: com.erp.erp_mask.controller
 * @Author: wang
 * @CreateTime: 2024-05-13  18:27
 * @Description: TODO
 * @Version: 1.0
 * @effect:
 */
@RestController
@RequestMapping("/cli")
public class TSupplierController {
    @Resource
    public TSupplierService tSupplierService;

    @GetMapping("/index")
    public ModelAndView index() {
        return new ModelAndView("/cli/supplier");
    }

    //主查询
    @GetMapping("/search")
    public Result search(String cliname, String cliaddress, Long pageNo, Long pageSize) {
        return Result.success(tSupplierService.searchTsup(cliname, cliaddress, pageNo, pageSize));
    }

    @DeleteMapping("/del")
    public Result del(Long id) {
        try {
            tSupplierService.removeById(id);
            return Result.success("删除成功!");
        } catch (Exception e) {
            return Result.fail("删除失败!");
        }
    }

    @PostMapping("/addList")
    public Result addList(@RequestBody TSupplier tSupplier) {
        try {
            tSupplierService.addList(tSupplier);
            return Result.success("添加成功!");
        } catch (Exception e) {
            return Result.fail("添加失败!");
        }
    }

    @PutMapping("/edit")
    public Result edit(@RequestBody TSupplier tSupplier) {
        try {
            tSupplierService.updateById(tSupplier);
            return Result.success("修改成功!");
        } catch (Exception e) {
            return Result.fail("修改失败!");
        }
    }

    //供应商下拉列表
    @GetMapping("/searchList")
    public Result searchList() {
        return Result.success(tSupplierService.list());
    }
}
